package com.ruoyi.db.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.DbTable;
import com.ruoyi.db.service.IDbTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据库模型之信息Controller
 * 
 * @author ruoyi
 * @date 2022-07-10
 */
@RestController
@RequestMapping("/db/table")
public class DbTableController extends BaseController
{
    @Autowired
    private IDbTableService dbTableService;

    /**
     * 查询数据库模型之信息列表
     */
    @PreAuthorize("@ss.hasPermi('db:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbTable dbTable)
    {
        startPage();
        List<DbTable> list = dbTableService.selectDbTableList(dbTable);
        return getDataTable(list);
    }

    /**
     * 导出数据库模型之信息列表
     */
    @PreAuthorize("@ss.hasPermi('db:table:export')")
    @Log(title = "数据库模型之信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DbTable dbTable)
    {
        List<DbTable> list = dbTableService.selectDbTableList(dbTable);
        ExcelUtil<DbTable> util = new ExcelUtil<DbTable>(DbTable.class);
        util.exportExcel(response, list, "数据库模型之信息数据");
    }

    /**
     * 获取数据库模型之信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('db:table:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dbTableService.selectDbTableById(id));
    }

    /**
     * 新增数据库模型之信息
     */
    @PreAuthorize("@ss.hasPermi('db:table:add')")
    @Log(title = "数据库模型之信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbTable dbTable)
    {
        return toAjax(dbTableService.insertDbTable(dbTable));
    }

    /**
     * 修改数据库模型之信息
     */
    @PreAuthorize("@ss.hasPermi('db:table:edit')")
    @Log(title = "数据库模型之信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbTable dbTable)
    {
        return toAjax(dbTableService.updateDbTable(dbTable));
    }

    /**
     * 删除数据库模型之信息
     */
    @PreAuthorize("@ss.hasPermi('db:table:remove')")
    @Log(title = "数据库模型之信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dbTableService.deleteDbTableByIds(ids));
    }
}
